package com.ruoyi.paper.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.paper.domain.ExamPaperLib;
import com.ruoyi.paper.service.IExamPaperLibService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试卷题目Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Controller
@RequestMapping("/jxsx/paperLib")
public class ExamPaperLibController extends BaseController
{
    private String prefix = "jxsx/lib";

    @Autowired
    private IExamPaperLibService examPaperLibService;

    @RequiresPermissions("jxsx:lib:view")
    @GetMapping()
    public String lib()
    {
        return prefix + "/lib";
    }

    /**
     * 查询试卷题目列表
     */
    @RequiresPermissions("jxsx:lib:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamPaperLib examPaperLib)
    {
        startPage();
        List<ExamPaperLib> list = examPaperLibService.selectExamPaperLibList(examPaperLib);
        return getDataTable(list);
    }

    /**
     * 导出试卷题目列表
     */
    @RequiresPermissions("jxsx:lib:export")
    @Log(title = "试卷题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamPaperLib examPaperLib)
    {
        List<ExamPaperLib> list = examPaperLibService.selectExamPaperLibList(examPaperLib);
        ExcelUtil<ExamPaperLib> util = new ExcelUtil<ExamPaperLib>(ExamPaperLib.class);
        return util.exportExcel(list, "试卷题目数据");
    }

    /**
     * 新增试卷题目
     */
    @RequiresPermissions("jxsx:lib:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存试卷题目
     */
    @RequiresPermissions("jxsx:lib:add")
    @Log(title = "试卷题目", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamPaperLib examPaperLib)
    {
        return toAjax(examPaperLibService.insertExamPaperLib(examPaperLib));
    }

    /**
     * 修改试卷题目
     */
    @RequiresPermissions("jxsx:lib:edit")
    @GetMapping("/edit/{paperLibId}")
    public String edit(@PathVariable("paperLibId") String paperLibId, ModelMap mmap)
    {
        ExamPaperLib examPaperLib = examPaperLibService.selectExamPaperLibByPaperLibId(paperLibId);
        mmap.put("examPaperLib", examPaperLib);
        return prefix + "/edit";
    }

    /**
     * 修改保存试卷题目
     */
    @RequiresPermissions("jxsx:lib:edit")
    @Log(title = "试卷题目", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamPaperLib examPaperLib)
    {
        return toAjax(examPaperLibService.updateExamPaperLib(examPaperLib));
    }

    /**
     * 删除试卷题目
     */
    @RequiresPermissions("jxsx:lib:remove")
    @Log(title = "试卷题目", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examPaperLibService.deleteExamPaperLibByPaperLibIds(ids));
    }
}
